<?php
/**
 * @package Joomla
 * @subpackage Jmonoslideshow
 * @copyright (C) 2010 - Matthieu BARBE - www.ccomca.com
 * @license GNU/GPL v2
 * 
 * Jmonoslideshow is a Joomla extension for Monoslideshow.
 *
 * Jmonoslideshow uses :
 * Monoslideshow (http://www.monoslideshow.com/)
 * Plupload (http://www.plupload.com/) by Moxicode Systems
 * json class by Michal Migurski, Matt Knapp, Brett Stimmerman
 * jquery a JavaScript Library (http://jquery.com/)
 * getid3 library (http://getid3.sourceforge.net/)
 * swfobject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file (http://code.google.com/p/swfobject/)
 * Chained Selects jQuery Plugin (http://www.appelsiini.net/2010/jquery-chained-selects)
 *
 * Jmonoslideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the Jmonoslideshow Component
 *
 * @package    Jmonoslideshow
 * @subpackage Views
 */

class JmonoslideshowViewMedias extends JView
{
	
	protected $items;
	protected $pagination;
	protected $state;
	
	/**
	 * Execute and display a layout script.
	 *
	 * @param	string $tpl	The name of the layout file to parse.
	 *
	 * @return 	void|JError
	 *
	 * @see		JView::display
	 */
	public function display($tpl = null) 
	{
		// Get data from the model
		$items 			= $this->get('Items');
		$pagination 	= $this->get('Pagination');
		$state 			= $this->get('State');
		$this->authors 	= $this->get('Authors');

		// Check for errors.
		if (count($errors = $this->get('Errors'))) 
		{
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}

		// Assign data to the view
		$this->items = $items;
		$this->pagination = $pagination;
		$this->state = $state;

		// Set the toolbar
		$this->addToolBar();

		// Prepare the document
		$this->prepareDocument();

		// Display the template
		parent::display($tpl);
	}
	
	/**
	 * Setting the toolbar
	 *
	 * @return 	void
	 */
	protected function addToolBar() 
	{
		$canDo	= JmonoslideshowHelper::getActionsImages($this->state->get('filter.category_id'));
		$user		= JFactory::getUser();
		$state = $this->get('State');
		$published = $state->get('filter.published');
		$published	= $published ? $published[0] : '';
		
		
		
		
		JToolBarHelper::title(   JText::_( 'COM_JMONOSLIDESHOW_JMONOSLIDESHOW_MEDIAS' ), 'media' );
		if ($canDo->get('core.create') || (count($user->getAuthorisedImages('com_jmonoslideshow', 'core.create'))) > 0 ) 
		{
			JToolBarHelper::addNew('media.add', 'JTOOLBAR_NEW');
		}
		if (($canDo->get('core.edit')) || ($canDo->get('core.edit.own')))
		{
			JToolBarHelper::editList('media.edit', 'JTOOLBAR_EDIT');
		}
	
		if ($published == -2 && $canDo->get('core.delete')) {
			JToolBarHelper::deleteList('', 'medias.delete', 'JTOOLBAR_EMPTY_TRASH');
			
		} else if ($canDo->get('core.edit.state')) {
			JToolBarHelper::trash('medias.trash');
			
		}
		
		
		if ($canDo->get('core.edit.state')) 
		{
			JToolBarHelper::divider();
			JToolBarHelper::publish('medias.publish', 'JTOOLBAR_PUBLISH', true);
			JToolBarHelper::unpublish('medias.unpublish', 'JTOOLBAR_UNPUBLISH', true);
		}
		
		JToolBarHelper::divider();
		JToolBarHelper::checkin('medias.checkin');
		
		
	}
	
	/**
	 * Method to set up the document properties
	 *
	 * @return void
	 */
	protected function prepareDocument() 
	{
	}

}//class